(function(){
	nsbase.views.gameList = new GameListFunc();

	function GameListFunc () {
		
		var _self = this;

		_self.init = _init;
		var clientResource = nsbase.resources.clientResource;
		function _init (type) {
			initGameType(type);
		}

		function initGameType (type) {
      		$(".nav_menu li.Online").addClass("selected");
			var gameTypeEnum  = nsbase.enums.gameTypeEnum.getEnumByValue(type);
			$("#gameType").text(gameTypeEnum.text);
			initGrid(type);
		}

		function initGrid (gameType) {
			var gridConfig = {
				renderTo:"gridContainer",
				height:500,
				rowNumber:true,
				columns:[
					{title:clientResource.columnGameName,dataIndex:"map_game_name",width:340},
					{title:clientResource.columnGameStartDate,dataIndex:"start_date",width:200},
					{title:clientResource.columnGameLength,dataIndex:"length",width:200},
					{title:clientResource.columnGameDuration,dataIndex:"duration",width:200}
				],
				rowSelectable:"none",
				paggingBar: {
					remote: true,
					pageIndex: 1,
					pageSize: 8
				},
				store:{
					data: {
						list_type:gameType
					}, 
					url: nsbase.config.actionUrl.game.getMapGameList,
				}
			}
			var gridEvents = nsbase.controls.grid.setting.eventEnums;
			var grid = new nsbase.controls.grid(gridConfig);
			grid.on(gridEvents.rowClick,function(sender,rowData){
				 location.href = nsbase.config.actionUrl.game.mapGameDetail+"?game_id="+rowData.map_game_id;
			});
		}
	}
})();